package com.lalnou3g.hm0419;

import java.io.*;

/**
 * Created by dllo on 18/4/19.
 */
public class Test02 {
    public static void main(String[] args) {

//        File file = new File("a1");
//        file.delete();

        //读取a中的文件进行分割
        new Thread(new Runnable() {
            @Override
            public void run() {
                File srcfile = new File("Q2/a");
                File desFile = new File("a");

                BufferedReader br = null;
                PrintWriter pw = null;

                try {

                    br = new BufferedReader(new InputStreamReader(new FileInputStream(srcfile)));
                    if (!desFile.exists()) {
                        desFile.createNewFile();
                    }
                    pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(desFile)));

                    String pos = null;
                    int sum = 0;
                    int index = 0;

                    while ((pos = br.readLine())!=null ){

                        pw.print(pos);
                        sum += pos.length();
                        if (sum >= 400*1024*1024){

                            index ++;
                            pw.close();
                            pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File("a"+index))));
                            sum = 0;
                        }

                    }
                    pw.flush();

                } catch (Exception e) {
                    e.printStackTrace();
                }finally {

                    IOUtils.closeAll(pw,br);
                }


            }
        }).start();

        // 读取b中的文件进行分割
        new Thread(new Runnable() {
            @Override
            public void run() {


            }
        });


    }


}
